package com.vic.hutool.growth;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

/**
 * @author victor
 */
public class GrowthTest {
    
    // 高释配置
    static String testingUrl = "http://api.growth-ring.com"; //:7000
    // 测题
    static String getQuestionUrl = "/psychological-evaluation/evaluation/t-questions/questions";
    // 作答提交
    static String submitAnswerUrl = "/psychological-evaluation/evaluation/t-questions/submit";
    // 获取报告
    static String getReportUrl = "/psychological-evaluation/evaluation/t-exam/report";
    // 获取测验情况
    static String getSituationUrl = "/psychological-evaluation/evaluation/t-questions/situation";
    // 合作伙伴id
    static String partnerId = "rlw20211219125415";
    // 供应商分配的私钥
    static String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCm4svVplUq7WyntqStJKAkS3VLW5zhHeeiJnZQM8KcVNpdA3IVOie/2F8NGKiw7TDHY7s+YcCszOw66m/imcggSlCsdVPeH3aGYhAHTbHVGqD3v7wirVcj6VY86FT3/2eWCjpEPYE8TARz5kQtIWvJAC3CpdfQ2Rl42QZAHIMTmBR0r6GMxDBbMBvWZ9NEr6dqY9+r7IWjwdgQ6EtzxmF7wnbSIy0is5XwKbuLp287ahnpRrBx4LEm3VtVDG3KS2ien5auHT4/t7hNoLix6v7K5bqmLTZ9bqKuAIhmVQhZcJCy+IjRappwEp03x0/4GzS0Fl/2Qd3Z/yFR5Z9qE9QTAgMBAAECggEBAICPOiMt7XISUJ+qTZWsH0mWb5dLzcCFvwjkxEPoe8TegREiNGIx2KkrT53RHzKcpfUT2QynVTxI6LpCG0re2JI3bYpNH/x/FFlVda+KpLHbv6DbLV0xV22stOhaugoJ0Ix++H/VOZdvoAaAnoh9tIC1CItoIqcad0rnNK9yx27xfGAgqRj9fZrYc1fq2wbFdBF7weFFCbLwNWc1GdX/OaSf3c6tNhke3KyEhpjSciYJLOCE3BhUBvfJkkxTSo1r3VbFhscWWveYWzRUigEraCiRGQ5TkmxSK4ojYRcQakbODnm0X9sAf/6R/bZ4CU0FtJPvDMZhO/QfY7DUEpynFOECgYEA0jHRrWPLvS0a4IDvuQZkBV1Xw1uVT2AY1FIt/cQWoVaHC/bHbtQrNkEffK+kqfTvKlVE6mOOEgPguPM1SIeDCA2W1ohLoz3c3Y9YjAumoC5HaDVoTTblj063gcrQBsmYWPfeL8OmlkeMNZosRynzu771i5vJRV/6P2KCB3mA03sCgYEAy0DnipRVtRuTFf3D3UPMv9d7LsayU+hl4wWIWgXXuto1VJLKkzlsbM9Vmc+fc2GAGnUodcfRpYQ9ifuBYARE1DS7kQR1N4KNkp/HH4H2uFffnUwa0MENDpBIse86uTeICHkZJK0tTKoAK+Fcmt3rQ87jBiksbouL+jkEWRwkskkCgYBKF09+m+fMJiMMMcbOZIdLMMznyteFpCz8Yn9drQoBEtwFhpZj5ZvZwvjTXaJgWjsXo/jn2fHRPdavuuL0TvgMFaYuttpaj0rUOlwO+WhhnA6FmBXM6eXfLvMWaCQN0G/IJI8ILSICZPPyTQcAirQkYLpy3JYEw0EVqKaG9fhIEwKBgFVdZCHS3RBcjXEODKYwpJzqHoVt1FXjZG9t0m+kxo9muEFWCZi95Gjqx5P7HIf0Kj5yeFTHYKi4mrQKGrM99758i06D5csznMw5KQN1rS6NUZCZ9yU3/4jfVnjM9gf2Z77PRZ0e0sjBGaNUWnV8wSPQj4712gBvwZGNQuM+K7dpAoGAUnOz7NaEreClSw1tJq6D7HLRN0LuWwpH+wyawOW3IO6aw9Gn0UOV8BOlOFGkfc/xNSTgTrMxh/9kmy1SAr41Fly+QNoKGQ2Dzrv/vlRcTxC7u6GwsND8a4QP+/GPizBp9dh1n+DqAxH5Qo3wWfMJRX+czn5dUX2W8cXFe4qmUwQ=";
    // 个人职场驱力id
    static String pwdId = "20211219225413001154463";
    // 个人职场驱力名称
    static String pwdName = "个人职场驱力测评";
    // 水电煤id
    static String wegId = "675876490843254868001936";
    // 水电煤名称
    static String wegName = "水电煤测评";


    public static void main(String[] args) {

        // 678960037124632650008891
//        String examId = "681174381648408593004361";

//        getReport(examId);

        // result:{"code":"200","msg":"","subCode":null,"subMsg":null,"result":{"examId":"680891309992439843004859","peId":"675876490843254868001936","examStatus":1,"createTime":null,"reportId":null,"userInfo":{"userId":"1c7809abe13045309fc7ffd8caea889b","name":null,"birthday":null,"gender":null,"age":null,"area":null}},"ex":"","traceId":"","serverTime":1642503631793}

//        getSit(examId);

//        submit(examId);
        getQuestions();

    }

    private static void getReport(String examId) {

        GrowthGetReportReq req = new GrowthGetReportReq();
        req.setExamId(examId);

        GrowthCommonReq commonReq = new GrowthCommonReq();
        commonReq.setPartnerId(partnerId);
        commonReq.setBizContent(JSON.toJSONString(req));
        commonReq.setSign(GrowthUtils.getSign(commonReq.getBizContent(), privateKey));

        String url = testingUrl + getReportUrl;
        String result = HttpRequest.post(url)
                    .body(JSON.toJSONString(commonReq))
                    .execute().body();
        System.out.println("url: " + url);
        System.out.println("param: " + JSON.toJSONString(commonReq));
        System.out.println(result);
    }

    private static void getSit(String examId) {
        GrowthGetSituationReq req = new GrowthGetSituationReq();
        req.setExamId(examId);

        GrowthCommonReq commonReq = new GrowthCommonReq();
        commonReq.setPartnerId(partnerId);
        commonReq.setBizContent(JSON.toJSONString(req));
        commonReq.setSign(GrowthUtils.getSign(commonReq.getBizContent(), privateKey));

        String url = testingUrl + getSituationUrl;
        String result = HttpRequest.post(url)
                    .body(JSON.toJSONString(commonReq))
                    .execute().body();
        System.out.println("url: " + url);
        System.out.println("param: " + JSON.toJSONString(commonReq));
        System.out.println(result);
    }


    private static void submit(String examId) {

        GrowthSubmitAnswerReq req = new GrowthSubmitAnswerReq();

        GrowthSubmitAnswerUserInfoReq userInfoReq = new GrowthSubmitAnswerUserInfoReq();
        userInfoReq.setUserId("c32d4cdba9654823aaa63817eaf75a33");

        req.setExamId(examId);
        req.setUserInfo(userInfoReq);

        List<GrowthSubmitAnswerQuestionReq> questions = new ArrayList<>();

        // 1
        GrowthSubmitAnswerQuestionReq q1 = new GrowthSubmitAnswerQuestionReq();
        q1.setQuestionId("675880248922861587010834");

        List<GrowthSubmitAnswerOptionReq> answersa = new ArrayList<>();
        GrowthSubmitAnswerOptionReq optionReqa = new GrowthSubmitAnswerOptionReq();
        optionReqa.setOptionId("675883170515644476011292");
        answersa.add(optionReqa);
        q1.setAnswer(answersa);
        questions.add(q1);

        // 2
        GrowthSubmitAnswerQuestionReq q2 = new GrowthSubmitAnswerQuestionReq();
        q2.setQuestionId("675880248939638809010673");

        List<GrowthSubmitAnswerOptionReq> answersb = new ArrayList<>();
        GrowthSubmitAnswerOptionReq optionReqb = new GrowthSubmitAnswerOptionReq();
        optionReqb.setOptionId("675883170524033039011265");
        answersb.add(optionReqb);
        q2.setAnswer(answersb);
        questions.add(q2);

        // 3
        GrowthSubmitAnswerQuestionReq q3 = new GrowthSubmitAnswerQuestionReq();
        q3.setQuestionId("675880248939638792010175");

        List<GrowthSubmitAnswerOptionReq> answersc = new ArrayList<>();
        GrowthSubmitAnswerOptionReq optionReqc = new GrowthSubmitAnswerOptionReq();
        optionReqc.setOptionId("675883170524033104011363");
        answersc.add(optionReqc);
        q3.setAnswer(answersc);
        questions.add(q3);

        // 4
        GrowthSubmitAnswerQuestionReq q4 = new GrowthSubmitAnswerQuestionReq();
        q4.setQuestionId("675880248939638807010436");

        List<GrowthSubmitAnswerOptionReq> answers4 = new ArrayList<>();
        GrowthSubmitAnswerOptionReq optionReq4 = new GrowthSubmitAnswerOptionReq();
        optionReq4.setOptionId("675883170524033123011895");
        answers4.add(optionReq4);
        q4.setAnswer(answers4);
        questions.add(q4);

        // 5
        GrowthSubmitAnswerQuestionReq q5 = new GrowthSubmitAnswerQuestionReq();
        q5.setQuestionId("675880248939638875010412");

        List<GrowthSubmitAnswerOptionReq> answers5 = new ArrayList<>();
        GrowthSubmitAnswerOptionReq optionReq51 = new GrowthSubmitAnswerOptionReq();
        optionReq51.setOptionId("675883170524033106011563");
        answers5.add(optionReq51);
        q5.setAnswer(answers5);
        questions.add(q5);

        // 6
        GrowthSubmitAnswerQuestionReq q6 = new GrowthSubmitAnswerQuestionReq();
        q6.setQuestionId("675880248939638866010129");

        List<GrowthSubmitAnswerOptionReq> answers6 = new ArrayList<>();
        GrowthSubmitAnswerOptionReq optionReq6 = new GrowthSubmitAnswerOptionReq();
        optionReq6.setOptionId("675883170524033054011176");
        answers6.add(optionReq6);
        q6.setAnswer(answers6);
        questions.add(q6);

        req.setQuestions(questions);


        GrowthCommonReq commonReq = new GrowthCommonReq();
        commonReq.setPartnerId(partnerId);
        commonReq.setBizContent(JSON.toJSONString(req));
        commonReq.setSign(GrowthUtils.getSign(commonReq.getBizContent(), privateKey));

        System.out.println(JSON.toJSONString(commonReq));
        String url = testingUrl;
        String api = submitAnswerUrl;
        String result = HttpRequest.post(url + api)
                .body(JSON.toJSONString(commonReq))
                .execute().body();
        System.out.println("result: " + result);
    }


    private static void getQuestions() {
        GrowthGetQuestionReq req = new GrowthGetQuestionReq();
        req.setPeId(wegId);
        req.setUserId("001");

        GrowthCommonReq commonReq = new GrowthCommonReq();
        commonReq.setPartnerId(partnerId);
        commonReq.setBizContent(JSON.toJSONString(req));
        commonReq.setSign(GrowthUtils.getSign(commonReq.getBizContent(), privateKey));

        String url = testingUrl;
        String api = getQuestionUrl;
        String result = HttpRequest
                .post(url + api)
                .body(JSON.toJSONString(commonReq))
                .execute().body();
        System.out.println("result: " + result);
    }
}
